package com.ljh.extensions.rabbit.config;

import com.ljh.extensions.rabbit.constants.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: Themberfue
 * @date: 2025/5/2 11:16
 * @description:
 */
@Configuration
public class DelayConfig {
    @Bean("delayQueue")
    public Queue delayQueue() {
        return QueueBuilder.durable(Constants.DELAY_QUEUE)
                .build();
    }
    @Bean("delayExchange")
    public DirectExchange delayExchange() {
        return ExchangeBuilder.directExchange(Constants.DELAY_EXCHANGE)
                .durable(true)
                .delayed() // ? 设置队列为延迟队列
                .build();
    }
    @Bean("delayBinding")
    public Binding delayBinding(@Qualifier("delayExchange") DirectExchange exchange, @Qualifier("delayQueue") Queue queue) {
        return BindingBuilder.bind(queue)
                .to(exchange)
                .with("delay");
    }
}
